﻿Public Class WebService
    Dim paramConfig As PL.MetaSDK.Configuration_PL

    Private Sub TESTButton_Click(sender As System.Object, e As System.EventArgs) Handles TESTButton.Click
        'TestNotificationMessage
        Dim SysBoxSvc As SystemBoxWSvc = New SystemBoxWSvc()
        Try
            Me.Cursor = Cursors.WaitCursor

            SysBoxSvc.TestNotificationConnection(paramConfig)

            TextEditWebServiceCatalog.Text = paramConfig.ServerWebServiceCatalog
            TextEditWebServiceDataSource.Text = paramConfig.ServerWebServiceDataSource
            TextEditWebServiceUser.Text = paramConfig.ServerWebServiceUser
            TextEditWebServiceUseExternal.Text = paramConfig.ServerWebServiceUseExternal

        Catch ex As Exception
            MessageWindow.ShowMessage(ex)
        Finally
            Me.Cursor = Cursors.Default
        End Try

    End Sub

    Private Sub WebService_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        paramConfig = New PL.MetaSDK.Configuration_PL()
        Try
            Dim cnParameter() As String = Split(AppManager.ConnectionString, ";")

            For i As Integer = 0 To UBound(cnParameter)
                Select Case Mid(cnParameter(i), 1, InStr(cnParameter(i), "="))
                    Case "Data Source="
                        paramConfig.ClientDataSource = Replace(cnParameter(i), "Data Source=", "") ' CN.Database  'AppManager.DbName
                    Case "Initial Catalog="
                        paramConfig.ClientCatalog = Replace(cnParameter(i), "Initial Catalog=", "") 'CN.DataSource ' AppManager.DbServerName
                    Case "User ID="
                        paramConfig.ClientUser = Replace(cnParameter(i), "User ID=", "") ' "sql_ssis"
                End Select
            Next

            Using appOpt As MetaApplication = New MetaApplication("SystemBox")
                paramConfig.ClientWEBServiceLocation = appOpt.MetaApplicationOptions("WebserviceAddress").DfltOptionValue
            End Using
            paramConfig.SecurityUserName = MetaValue.GetMetaValueByCode("OPT_BASIC_AUTHENTICATION_USER").Value
            paramConfig.SecurityPassword = MetaValue.GetMetaValueByCode("OPT_BASIC_AUTHENTICATION_PWD").Value
            paramConfig.ErrorFROM = MetaValue.GetMetaValueByCode("OPT_NOTIF_FROM_SUPPORT").Value
            paramConfig.ErrorTO = MetaValue.GetMetaValueByCode("OPT_NOTIF_TO_SUPPORT").Value
            paramConfig.ErrorSMTP = SCIEF.ActiveFramework.CommonExt.Base.AppManager.SMTPServer

            TextEditClientCatalog.Text = paramConfig.ClientCatalog
            TextEditClientDataSource.Text = paramConfig.ClientDataSource
            TextEditClientUser.Text = paramConfig.ClientUser
            TextEditWEBServiceLocation.Text = paramConfig.ClientWEBServiceLocation
            TextEditUserName.Text = paramConfig.SecurityUserName
            TextEditPassword.Text = paramConfig.SecurityPassword
            TextEditErrorFrom.Text = paramConfig.ErrorFROM
            TextEditErrorTo.Text = paramConfig.ErrorTO
            TextEditSMTP.Text = paramConfig.ErrorSMTP

        Catch ex As Exception
            MessageWindow.ShowMessage(ex)
        End Try
    End Sub

End Class